package com.firstjianmo.fragmentbestpractice.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.firstjianmo.fragmentbestpractice.R;
import com.firstjianmo.fragmentbestpractice.model.News;

/**
 * Created by pc on 2016/12/3.
 */

public class    NewsContentFragment extends Fragment {

    private View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.news_content_frag, container, false);
        return view;
    }

    public void refresh(News news){
        if (News.isEmptyNews(news)){
            Toast.makeText(view.getContext(), "读取新闻失败", Toast.LENGTH_LONG).show();
            return;
        }
        View newsContentLayout = view.findViewById(R.id.visibility_layout);
        newsContentLayout.setVisibility(View.VISIBLE);

        TextView newsTitleText = (TextView) view.findViewById(R.id.news_title);
        TextView newsContentText = (TextView) view.findViewById(R.id.news_content);
        newsTitleText.setText(news.getTitle());
        newsContentText.setText(news.getContent());
    }

}
